﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;


namespace Portal
{

    /// <summary>
    /// 权限拦截
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
    public class AuthorizeFilterAdminAttribute : ActionFilterAttribute
    {


        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            //地址
            var path = filterContext.HttpContext.Request.Path.ToLower();
            //忽略对Login登录页的权限判定
            if (path == "Admin/Login/Index".ToLower())
            {
                return;
            }
            //判定用户是否登录
            if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
            {
                filterContext.Result = new RedirectToRouteResult("Admin_default", new RouteValueDictionary(new { controller = "Login", action = "Expired" }));
            }

        }

    }

}
